<?php
include(dirname(dirname(dirname(__FILE__))) . '/bootstrap.php');

//引入分类插件类
include 'phpanalysis.class.php';

$str = isset($_REQUEST['str']) ? $_REQUEST['str'] : '';

$ret_tag = array();

if(!$str){
    echo json_encode($ret_tag);
    exit;
}

//岐义处理
//新词识别
$do_fork = $do_unit = true;

//多元切分
//词性标注
//是否预载全部词条
$do_multi = $do_prop = $pri_dict = false;

//初始化类
PhpAnalysis::$loadInit = false;
$pa = new PhpAnalysis('utf-8', 'utf-8', $pri_dict);

//载入词典
$pa->LoadDict();

//执行分词
$pa->SetSource($str);
$pa->differMax = $do_multi;
$pa->unitWord = $do_unit;

$pa->StartAnalysis( $do_fork );

$okresult = $pa->GetFinallyResult(';', $do_prop);

$pa_foundWordStr = $pa->foundWordStr;

$pa = '';

$words_arr = explode(';',$okresult);

$tag_arr = array_unique($words_arr);


foreach((array)$words_arr as $k=>$v){
    $check_tag = preg_match("/[\x7f-\xff]|[a-zA-z]/", $v);

    $tag_len = (int)(strlen($v) + mb_strlen($v,'UTF8')) / 2;

    if($tag_len >= 4 && $tag_len <= 14 && count($ret_tag)<10 && !empty($check_tag) && !strstr($v,';')){
        $ret_tag[] = $v;
    }
}

echo json_encode(implode(',',$ret_tag));

exit;

